package DBLayer;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


import ModelLayer.Forestilling;
import ModelLayer.Kunde;
import ModelLayer.Saede;
import ModelLayer.Salg;

public class DBSalgTest {
	private DBSalg dbSalg;

	@Before
	public void setUp() throws Exception {
		dbSalg = new DBSalg();
	}

	@After
	public void tearDown() throws Exception {
	}
	
	/**
	 * Test method for {@link DBLayer.DBSalg#insertSalg(ModelLayer.Salg)}.
	 * @throws Exception 
	 */
	@Test
	public void testInsertSalg() throws Exception 
	{
		Forestilling f = new Forestilling(7);
		Kunde k = new Kunde(7777777);
		byte b = 5;
		DBSaede dbSaede = new DBSaede();
		Saede saedeObj = dbSaede.getSaede(53, false);
		ArrayList<Saede> s = new ArrayList<Saede>();
		s.add(saedeObj);
		Salg sObject = new Salg("2012/05/15", b, true, f, k, s);
		dbSalg.insertSalg(sObject);
		//Normally you would delte the salg after inserting in an insert test but because we wanted to find the salg afterwords the delete was not implemented
	}
	
	@Test
	public void testFindSalg() {
		Salg sObject = dbSalg.getSalg(999, false);
		if(sObject != null)
		{
			System.out.print("\nDato: " + sObject.getDatoOprettet() + "\nAntal Billetter: "+ sObject.getBilletAntal() + "\nKundens Telefon: " + sObject.getKunde().getTelefonNr() + "\n");
		}
		fail("Salg not found");
	}
	/**
	 * Test method for {@link DBLayer.DBSalg#updateSalg(ModelLayer.Salg)}.
	 */
	@Test
	public void testUpdateSalg() 
	{
		byte ba = 5;
		Salg sObject = dbSalg.getSalg(1001, false);
		sObject.setBilletAntal(ba);
		
		dbSalg.updateSalg(sObject);
	}
	@Test
	public void getAllSalg()
	{
		dbSalg.getAllSalg(true);
	}	
	
	@Test
	public void testDeleteSalg() 
	{
		dbSalg.delete(1001);
	}
}
